package fr.m2i.cinescopeandroid;

import fr.m2i.xml.test.HitParade;
import android.os.Bundle;
import android.app.ListActivity;
//import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

/*
 * AccueilLibrairie
 *
 */
public class Cinescope extends ListActivity {

	private TextView textViewMessageAccueil;

	private Intent intentionBoxOffice;
	private Intent intentionHitParade;
	private Intent intentionTousLesFilms;
	private Intent intentionAvisDesCritique;

	@Override
	// -----------------
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.cinescope);

		textViewMessageAccueil = (TextView) findViewById(R.id.textViewMessageAccueil);
	} // / onCreate

	// ------------------------
	/**
	 * int position == position de l'item du menu
	 * 
	 */

	public void onListItemClick(ListView parent, View v, int position, long id) {

		try {
			if (position == 0) {
				intentionTousLesFilms = new Intent(this, TousLesFilms.class);
				startActivityForResult(intentionTousLesFilms, 1);
			}
			if (position == 1) {
				intentionBoxOffice = new Intent(this, BoxOffice.class);
				startActivityForResult(intentionBoxOffice, 2);
			}

			if (position == 2) {
				intentionHitParade = new Intent(this, HitParade.class);
				startActivityForResult(intentionHitParade, 3);
			}
			if (position == 3) {
				intentionAvisDesCritique = new Intent(this,
						AvisDesCritiques.class);
				startActivityForResult(intentionAvisDesCritique, 4);
			}
		} // / fin du try

		catch (Exception e) {
			textViewMessageAccueil.setText(e.getMessage());
		}
	} // / onListItemClick()

	// -------------------------
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		switch (requestCode) {
		case 1: // Box Office
			switch (resultCode) {
			case RESULT_OK:
				// --- Recuperation des donnees recues
				textViewMessageAccueil.setText("Vous avez regarder "
						+ data.getStringExtra("Tout les films"));
				return;
			case RESULT_CANCELED:
				textViewMessageAccueil.setText("Annulation Tous Les Films");
				return;
			} // / switch (resultCode)

		case 2: // Box Office
			switch (resultCode) {
			case RESULT_OK:
				// --- Recuperation des donnees recues
				textViewMessageAccueil.setText("Vous avez regarder "
						+ data.getStringExtra("Box Office"));
				return;
			case RESULT_CANCELED:
				textViewMessageAccueil.setText("Annulation Box Office");
				return;
			} // / switch (resultCode)

		case 3: // Hit Parade
			switch (resultCode) {
			case RESULT_OK:
				// --- Recuperation des donnees recues
				textViewMessageAccueil.setText("Vous avez regarder "
						+ data.getStringExtra("Hit Parade"));
				return;
			case RESULT_CANCELED:
				textViewMessageAccueil.setText("Annulation Hit Parade");
				return;
			}
		case 4: // Hit Parade
			switch (resultCode) {
			case RESULT_OK:
				// --- Recuperation des donnees recues
				textViewMessageAccueil.setText("Vous avez regarder "
						+ data.getStringExtra("Avis Des Critiques"));
				return;
			case RESULT_CANCELED:
				textViewMessageAccueil
						.setText("Annulation Avius des critiques");
				return;
			}
		} // / switch (requestCode)

	} // / onActivityResult

} // / class CineScope